import { normalize } from 'path';
import { workspace, WorkspaceConfiguration } from 'vscode';
import { ConfigConst } from '../constants';

/**
 * 本插件 vscode 配置
 *
 * @author chitanda
 * @date 2022-01-18 18:01:33
 * @export
 * @class Configs
 */
export class Configs {
  /**
   * vscode 配置对象
   *
   * @author chitanda
   * @date 2022-01-18 18:01:42
   * @readonly
   * @protected
   * @type {WorkspaceConfiguration}
   */
  protected get config(): WorkspaceConfiguration {
    return workspace.getConfiguration('ibiz-modeling-handlebars-preview');
  }

  /**
   * 模板路径
   *
   * @author chitanda
   * @date 2022-01-18 18:01:54
   * @readonly
   * @type {string}
   */
  get templateFolder(): string {
    const path = this.config.get<string>(ConfigConst.TEMPLATE_FOLDER);
    if (path && path.length > 0) {
      return normalize(path);
    }
    const folder = workspace.workspaceFolders![0];
    return normalize(folder.uri.fsPath);
  }

  /**
   * 模型路径
   *
   * @author chitanda
   * @date 2022-01-18 18:01:26
   * @readonly
   * @type {(string | undefined)}
   */
  get modelFolder(): string | undefined {
    const path = this.config.get<string>(ConfigConst.MODEL_FOLDER);
    if (path) {
      return normalize(path);
    }
  }
}
